// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'whatwg-fetch';
import 'custom-event-polyfill';
import 'core-js/stable/promise';
import 'core-js/stable/symbol';
import 'core-js/stable/string/starts-with';
import 'core-js/web/url';
import './public-path';
import Vue from 'vue'
import App from './App'
import {router} from './router'
import store from './store/store'
import i18n from './lang' 
import ElementUI from 'element-ui'
import './font/iconfont.css'
import './common/css/element-variables.scss'
import './common/css/reset.css'
import filters from './filters' //自定义过滤器，挂在到Vue全局
import autoFocus from '@/directives/autoFocus'
import waterMaker from '@/directives/waterMaker'
const mime = require("mime");

Vue.prototype.$mime = mime;

Vue.config.productionTip = false
Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))
Vue.use(autoFocus);
Vue.use(waterMaker);
Vue.use(ElementUI, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})

let instance = null;
function render(props = {}) {
  const { container } = props;

  instance = new Vue({
    router,
    store,
    i18n,
    render: (h) => h(App),
  }).$mount(container ? container.querySelector('#app') : '#app');
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped');
}

export async function mount(props) {
  console.log('[vue] props from main framework', props);
  // 主应用传递过来得props挂在到全局
  // 可以实现全局参数变化监控onGlobalStateChange，设置全局参数setGlobalState
  // 其中得router可以实现在子应用中，触发主应用路由跳转
  Vue.prototype.$qiankun_props = props
  props.appfunction();
  render(props);
}
export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
}